package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jt.mapper.ItemMapper;
import com.jt.pojo.Item;
import com.jt.vo.EasyUiTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {
	
	@Autowired
	private ItemMapper itemMapper;

	@Override
	public EasyUiTable findItemBypage(Integer page, Integer rows) {
		//查询分页
		int start=(page-1)*rows;
		List<Item> list=itemMapper.findBycount(start,rows);
		long total =itemMapper.selectCount(null);
		return new EasyUiTable(total,list);
	}
	//使用mybatis-plus
	public EasyUiTable findItemByPageMyabtis(Integer page,Integer rows){
		IPage<Item> iPage=new Page<>(page,rows);
		QueryWrapper<Item> QueryWrapper = new QueryWrapper<>();
		QueryWrapper.orderByDesc("updated");
		IPage<Item> selectPage = itemMapper.selectPage(iPage, QueryWrapper);
		long total = iPage.getTotal();
		List<Item> items = iPage.getRecords();
		return new EasyUiTable(total,items);
	}
}
